{% extends 'base.html' %}
{% load helpers %}
{% load form_helpers %}

{% block content %}
    <form action="" method="post" class="h-100 vstack">
        {% csrf_token %}
        <h1 class="mb-16">{% block title %}Renaming {{ selected_objects|length }} {{ obj_type_plural|bettertitle }} on {{ parent_name }}{% endblock %}</h1>
        <div class="row align-content-start flex-fill">
            <div class="col-md-7">
                <div class="card">
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                                <tr>
                                    <th>Current Name</th>
                                    <th>New Name</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for obj in selected_objects %}
                                    <tr{% if obj.new_name and obj.name != obj.new_name %} class="success"{% endif %}>
                                        <td>{{ obj.name }}</td>
                                        <td>{{ obj.new_name }}</td>
                                    </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="col-md-5">
                {% if form.non_field_errors %}
                    <div class="card border-danger">
                        <div class="card-header bg-danger-subtle border-danger text-body">
                            <strong>Errors</strong>
                        </div>
                        <div class="card-body">
                            {{ form.non_field_errors }}
                        </div>
                    </div>
                {% endif %}
                <div class="card">
                    <div class="card-header"><strong>Rename</strong></div>
                    <div class="card-body">
                        {% render_form form %}
                    </div>
                </div>
            </div>
        </div>
        <div class="nb-form-sticky-footer">
            <button type="submit" name="_preview" class="btn btn-primary">
                <span aria-hidden="true" class="mdi mdi-eye-outline me-4"></span><!--
                -->Preview
            </button>
            {% if '_preview' in request.POST and not form.errors %}
                <button type="submit" name="_apply" class="btn btn-primary">
                    <span aria-hidden="true" class="mdi mdi-check me-4"></span><!--
                    -->Apply
                </button>
            {% endif %}
            <a href="{{ return_url }}" class="btn btn-secondary">
                <span aria-hidden="true" class="mdi mdi-close me-4"></span><!--
                -->Cancel
            </a>
        </div>
    </form>
{% endblock %}
